async function refreshTokenIfNeeded() {
  // 假设userStore.user.tokenExpireTime为token过期时间戳
  const now = Date.now();
  const expireTime = this.user?.tokenExpireTime || 0;
  // 5分钟内即将过期则自动刷新
  if (expireTime && expireTime - now < 5 * 60 * 1000) {
    try {
      // 调用云函数/接口刷新token，假设cloudHelper.callCloud('oa', {action: 'refreshToken'})
      const res = await cloudHelper.callCloud('oa', { action: 'refreshToken' });
      if (res && res.token) {
        this.user.token = res.token;
        this.user.tokenExpireTime = res.tokenExpireTime;
        wx.setStorageSync('USER_TOKEN', res.token);
        wx.setStorageSync('USER_TOKEN_EXPIRE', res.tokenExpireTime);
        console.log('[Token] 自动续签成功');
      }
    } catch (e) {
      console.error('[Token] 自动续签失败', e);
    }
  }
}

const userStore = observable({
  async loginSilence() {
    await refreshTokenIfNeeded.call(this);
    // ... existing code ...
  },
  // ... existing code ...
}); 